package org.secangkirkopipanas.gxtcore.server.domain;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import net.sf.hibernate4gwt.pojo.java5.LazyPojo;

import org.secangkirkopipanas.gxtcore.domain.ISystemBusinessUnit;
import org.secangkirkopipanas.gxtcore.domain.ISystemGroup;

@Entity
@Table(name = "sys_group")
public class SystemGroup extends LazyPojo implements Serializable, ISystemGroup {

	private static final long serialVersionUID = 1L;

	public static final long SYSADMIN_GROUP_ID = 0;

	@Id
	@Column(name = "id", nullable = false, insertable = true, updatable = true)
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;

	@Column(name = "group_name", length = 50, nullable = false, insertable = true, updatable = true)
	private String name;

	@ManyToOne(targetEntity = SystemBusinessUnit.class)
	@JoinColumn(referencedColumnName = "id", nullable = false)
	private ISystemBusinessUnit businessUnit;

	@Column(name = "is_disabled", nullable = false, insertable = true, updatable = true)
	private boolean disabled = false;

	public SystemGroup() {
		super();
	}

	public SystemGroup(String name) {
		this(name, null);
	}

	public SystemGroup(String name, ISystemBusinessUnit businessUnit) {
		super();
		this.name = name;
		this.businessUnit = businessUnit;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public boolean isSystemAdminGroup() {
		return (SystemGroup.SYSADMIN_GROUP_ID == id);
	}

	public ISystemBusinessUnit getBusinessUnit() {
		return businessUnit;
	}

	public void setBusinessUnit(ISystemBusinessUnit businessUnit) {
		this.businessUnit = businessUnit;
	}

	public boolean isDisabled() {
		return disabled;
	}

	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}

}
